<?php
/**
 * Created by PhpStorm.
 * User: BlueIdeaLirui
 * Date: 2020/03/10
 * Time: 上午10.17
 */

namespace business\base\services;

class SynonymWordsService
{
    /**
     * 同义词查找
     * @param $word
     * @return array|false
     * @throws \yii\db\Exception
     */
    public static function find($word)
    {
        if (!empty($word)) {
            $sql = <<<sql
            SELECT
                f.word
            FROM
                b2b_search.synonym_words_filter f
            INNER JOIN 
                b2b_search.synonym_words_item i ON f.uid = i.synonym_words_uid 
            AND f.is_close = 0 
            AND f.is_deleted = 0
sql;
            $condition = " WHERE i.word_items = '$word'";
            $result = \Yii::$app->db->createCommand($sql . $condition)->queryScalar();

            return $result ? $result : $word;
        }

        return $word;
    }
}
